/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ez2find.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;

/**
 *
 * @author Owner
 */
@NamedQueries(value = {@NamedQuery(name = "listAllRegisterUsers", query = "SELECT u FROM RegisterUser u"),
    @NamedQuery(name = "findUserForConfirmation", query = "SELECT u FROM RegisterUser u WHERE u.encryptedId=:encryptedId AND u.confirmationCode=:confirmationCode"),
    @NamedQuery(name = "findUserByEmail", query = "SELECT u FROM RegisterUser u WHERE u.email=:email"),
    @NamedQuery(name = "loginUser", query = "SELECT u FROM RegisterUser u WHERE u.email=:email AND u.password=:pwd")
})
@Entity
public class RegisterUser implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Long id;
    private String encryptedId;
    private String confirmationCode;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date registerDate;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date loggedDate;
    private String email;
    private String password;
    private String status;
    private boolean adminUser;
    @ManyToOne()
    private Site defaultSite;
    private int numberOfPostings;
    @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
    private List<Post> posts;
    @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
    private List<Nick> handles;
    @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
    private List<Subscription> subscriptions;
    @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
    private List<Flag> flags;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getRegisterDate() {
        return registerDate;
    }

    public void setRegisterDate(Date registerDate) {
        this.registerDate = registerDate;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Site getDefaultSite() {
        return defaultSite;
    }

    public void setDefaultSite(Site defaultSite) {
        this.defaultSite = defaultSite;
    }

    public int getNumberOfPostings() {
        return numberOfPostings;
    }

    public void setNumberOfPostings(int numberOfPostings) {
        this.numberOfPostings = numberOfPostings;
    }

    public List<Post> getPosts() {
        return posts;
    }

    public void setPosts(List<Post> posts) {
        this.posts = posts;
    }

    public String getEncryptedId() {
        return encryptedId;
    }

    public void setEncryptedId(String encryptedId) {
        this.encryptedId = encryptedId;
    }

    public String getConfirmationCode() {
        return confirmationCode;
    }

    public void setConfirmationCode(String confirmationCode) {
        this.confirmationCode = confirmationCode;
    }

    public boolean getAdminUser() {
        return adminUser;
    }

    public void setAdminUser(boolean adminUser) {
        this.adminUser = adminUser;
    }
        public List<Nick> getNicks(){
        if (handles==null){
            handles=new ArrayList<Nick>();
        }
        return handles;
    }
    
    public List<Nick> getHandles() {
        if (handles==null){
            handles=new ArrayList<Nick>();
        }
        return handles;
    }

    public void setHandles(List<Nick> handles) {
        this.handles = handles;
    }

    public List<Subscription> getSubscriptions() {
        if (subscriptions==null){
            subscriptions=new ArrayList<Subscription>();
        }
        return subscriptions;
    }

    public void setSubscriptions(List<Subscription> subscriptions) {
        this.subscriptions = subscriptions;
    }

    public List<Flag> getFlags() {
        if (flags==null){
            flags=new ArrayList<Flag>();
        }
        return flags;
    }

    public void setFlags(List<Flag> flags) {
        this.flags = flags;
    }

    public Date getLoggedDate() {
        return loggedDate;
    }

    public void setLoggedDate(Date loggedDate) {
        this.loggedDate = loggedDate;
    }
}
